﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using com.subb.WebInformation;
using WebEntities;
using com.subb.ProductInformation;
using com.subb.WebFramework;
using WebsiteUI.Extensions;
using WebsiteUI.ActionFilters;
using WebEntities.Models.WebInfo;

namespace WebsiteUI.Controllers
{
    public class DetailController : Controller
    {
        /// <summary>
        /// 新闻信息类型详细页面
        /// </summary>
        /// <param name="id">新闻ID</param>
        [NewsViewCount]
        public ActionResult Index(int id = 0)
        {
            int cataId = 0;
            WI_NewsDAL ndal = new WI_NewsDAL();
            WI_News news = ndal.GetNews(id, false);
            if (news == null)
            {
                news = new WI_News();
            }
            else
            {
                cataId = news.CataID ?? 0;
            }
            ViewBag.ArgID = cataId; //作为参数传给圆圈局部视图

            //获取一级新闻目录以及新闻列表
            WI_NewsCataDAL ncdal = new WI_NewsCataDAL();
            WI_NewsCata ncata = ncdal.GetNewsCata(cataId);
            List<WI_News> leftNewsList = new List<WI_News>();  //左侧新闻栏列表
            List<WI_News> botNewsList = new List<WI_News>();  //下方新闻栏列表
            if (ncata != null)
            {
                botNewsList = ndal.GetAllNews(cataId, 0, 5);
                int miId = ncata.MenuItemID ?? 0;
                //如果少于1条新闻，自动读取协会动态的新闻。
                if (botNewsList.Count <= 1)
                {
                    botNewsList = ndal.GetAllNews(CommonFn.GetContentID("UnionNewsID"), 0, 6);
                    ncata = ncdal.GetNewsCata(CommonFn.GetContentID("UnionNewsID"));
                    if (ncata != null)
                    {
                        miId = ncata.MenuItemID ?? 0;
                    }
                }
                FW_MenuItemDAL midal = new FW_MenuItemDAL();
                FW_MenuItem mitem = midal.GetMenuItem(miId);
                if (mitem != null)
                {
                    leftNewsList = ndal.GetAllNewsByMenuID(mitem.MenuID ?? 0, 0, 8);
                }
            }

            ViewBag.LeftNewsList = leftNewsList;
            ViewBag.BotNewsList = botNewsList;

            return View(news);
        }
        /// <summary>
        /// 产品的详细页面
        /// </summary>
        /// <param name="id">产品ID</param>
        /// <returns></returns>
        public ActionResult Product(int id = 0)
        {
            ViewBag.MenuItemID = CommonFn.GetContentID("ProdMuItemID");
            PP_ProductDAL DAL = new PP_ProductDAL();
            PP_Product obj = DAL.GetUiProduct(id);
            if (obj == null) { obj = new PP_Product(); }
            return View(obj);
        }

        /// <summary>
        /// 专家人物详细页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Expert(int id = 0)
        {
            ViewBag.MenuItemID = CommonFn.GetContentID("ExpertMuItemID");
            WI_ExpertsDAL DAL = new WI_ExpertsDAL();
            WI_Experts obj = DAL.GetExpertsByView(id);
            if (obj == null) { obj = new WI_Experts(); }
            return View(obj);
        }

        /// <summary>
        /// 英才招聘详细页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Job(int id = 0)
        {
            ViewBag.MenuItemID = CommonFn.GetContentID("JobsMuItemID");
            WI_JobsDAL jdal = new WI_JobsDAL();
            WI_Jobs job = jdal.GetJob(id);
            //获取5条其他招聘信息
            int ttlCount;
            List<WI_Jobs> joblist = jdal.GetAllJobs(JobShowStatus.Show, 0, 5, out ttlCount);
            ViewBag.OtherJobs = joblist;
            return View(job);
        }

    }
}
